package bignum;

import java.math.BigDecimal;

/**
 * 用来存储一个超出double类型的帧整数
 * @author Raymond
 * @create 2025/4/23 14:17
 */
public class MyBigDecimal {
    public static void main(String[] args) {
        BigDecimal a = new BigDecimal("1.3847831222222222222222222222222222222222222222222");
        BigDecimal b = new BigDecimal("2.1");
        //加
        System.out.println("a.add(b) = " + a.add(b));
        //减
        System.out.println("a.subtract(b) = " + a.subtract(b));
        //乘
        System.out.println("a.multiply(b) = " + a.multiply(b));
        //除 有可能抛出Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
        System.out.println("a.divide(b) = " + a.divide(b));
        //在使用除法的时候如果被除数是除不净的会抛异常 ，需要限制下除完之后的长度
        System.out.println("a.divide(b,BigDecimal.ROUND_CEILING) = " + a.divide(b, BigDecimal.ROUND_CEILING));
    }
}
